import requests
import pytest

# 添加用户分组
def add_user_group():
    url = "http://example.com/api/user_groups"
    data = {"name": "新分组"}
    response = requests.post(url, json=data)
    assert response.status_code == 201
    return response.json()["id"]

# 删除用户分组
def delete_user_group(group_id):
    url = f"http://example.com/api/user_groups/{group_id}"
    response = requests.delete(url)
    assert response.status_code == 204

# 添加客服话术
def add_customer_service_script():
    url = "http://example.com/api/customer_service_scripts"
    data = {"content": "新话术"}
    response = requests.post(url, json=data)
    assert response.status_code == 201
    return response.json()["id"]

# 删除客服话术
def delete_customer_service_script(script_id):
    url = f"http://example.com/api/customer_service_scripts/{script_id}"
    response = requests.delete(url)
    assert response.status_code == 204

# 添加用户标签
def add_user_tag():
    url = "http://example.com/api/user_tags"
    data = {"name": "新标签"}
    response = requests.post(url, json=data)
    assert response.status_code == 201
    return response.json()["id"]

# 删除用户标签
def delete_user_tag(tag_id):
    url = f"http://example.com/api/user_tags/{tag_id}"
    response = requests.delete(url)
    assert response.status_code == 204

# 测试用例
def test_add_and_delete():
    group_id = add_user_group()
    script_id = add_customer_service_script()
    tag_id = add_user_tag()

    delete_user_group(group_id)
    delete_customer_service_script(script_id)
    delete_user_tag(tag_id)
